home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT11 / CURSKEEP.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  5.9 KB  |  131 lines

  1. ;       Program CursKeep ( Chapter 11 )
  2. ;
  3.     page    55,132
  4. NewFunc equ     0E0h
  5. CheckIn equ     51h                     ; subfunction "check installation"
  6.  
  7. _Text   segment para public 'CODE'
  8.     assume  cs:_Text
  9. ;====================  Resident data =====================================      
  10. NumFun  db      ?
  11. SaveAX  dw      ?
  12. SaveBX  dw      ?
  13. SaveCX  dw      ?
  14. SaveDX  dw      ?
  15. ;=====================  Resident code ====================================
  16. Handler proc    near                    ; additional handler for interrupt 10h
  17.     cmp     ah,NewFunc              ; additional function of INT 10h?
  18.     je      Addf                    ; new handler for that function
  19. Process:pushf
  20.     mov     NumFun,ah               ; save number of function called
  21.     cmp     ah,1                    ; is it function "Set Cursor Type"
  22.     jne     VidCall                 ; if not call standard handler
  23.     cmp     cl,8                    ; is cursor end line greater than 7
  24.     jb      VidCall                 ; if not, call standard handler
  25.     mov     cl,7                    ;   else replace cursor end line with 7
  26.     shr     ch,1                    ;   else divide its value by 2
  27. VidCall:call    dword ptr OldHand       ; call BIOS video interrupt
  28.     cmp     NumFun,0                ; was it function "Set Video Mode"?
  29.     je      ModCurs                 ; if it was, reprogram cursor type
  30.     cmp     NumFun,11h              ; was it function "Load Character Set"?
  31.     je      ModCurs                 ; if it was, reprogram cursor type
  32.     iret                            ; return from interrupt handler
  33. ModCurs:pushf
  34.     mov     SaveAX,ax               ; save AX in memory, without using stack
  35.     mov     SaveBX,bx               ; save BX in memory, without using stack
  36.     mov     SaveCX,cx               ; save CX in memory, without using stack
  37.     mov     SaveDX,dx               ; save DX in memory, without using stack
  38.     
  39.     mov     ah,03h                  ; function 03 - get cursor position
  40.     mov     bx,0
  41.     pushf
  42.     call    dword ptr OldHand       ; call BIOS video interrupt
  43.  
  44.     mov     ah,ch
  45.     and     ah,1Fh
  46.     cmp     ah,6
  47.     jb      ModCL
  48.     and     ch,07h
  49.     or      ch,06h
  50. ModCL:  mov     cl,07h  
  51.     mov     ah,01h                  ; function 01 - get cursor position
  52.     pushf
  53.     call    dword ptr OldHand       ; call BIOS video interrupt
  54.     mov     dx,SaveDX
  55.     mov     cx,SaveCX               ; restore AX from memory
  56.     mov     bx,SaveBX
  57.     mov     ax,SaveAX               ; restore CX from memory
  58.     popf
  59. NoMod:  iret                            ; return from interrupt handler
  60. ;===    Pass the control to the standard handler of the interrupt 10h   
  61. ToOld10:jmp     dword ptr OldHand
  62. OldHand dw      ?,?
  63. OldOff  equ     OldHand[+0]
  64. OldSeg  equ     OldHand[+2]
  65. ;===    Process additional function of interrupt 10h
  66. Addf:   cmp     al,CheckIn              ; is installation check required?
  67.     jne     ToOld10
  68. Inst:   xchg    ah,al                   ; value to be returned into AX
  69.     iret                            ; return from handler   
  70. Handler endp
  71.  
  72. ;===    Installation part of the program
  73. BegInst label   byte
  74. ComSeg  dw      ?
  75. PSPAddr dw      ?
  76. Start:  mov     PSPAddr,es              ; save address of PSP
  77.     mov     sp,0F000h               ; set the stack
  78. ;===    Free the environment memory block
  79.     mov     es,es:[2Ch]             ; address of environment block into ES 
  80.     mov     ah,49h                  ; function 49h - free memory block
  81.     int     21h                     ; DOS service call
  82. ;===
  83.     mov     es,PspAddr              ; set ES to point to PSP
  84.     mov     ComSeg,cs               ; save current command segment
  85.     mov     ds,ComSeg               ; DS = CS - data and code are the same 
  86. ;===    check whether the program is alrady installed
  87.     mov     ah,NewFunc              ; new funtion of INT 10h
  88.     mov     al,CheckIn              ; AL - installation check
  89.     int     10h                     ; call interrupt 10h - timer tick
  90.     cmp     ah,Checkin              ; does AH contain function number?
  91.     je      Already                 ; if YES, handler is already installed
  92. ;===    modifying IVT
  93.     mov     ax,3510h                ; function 35h - Get Interrupt Vector
  94.     int     21h                     ; DOS service call
  95.     mov     OldOff,bx               ; save offsett of old handler for 10h
  96.     mov     OldSeg,es               ; save segment of old handler for 10h
  97.     mov     dx,offset Handler       ; address of handler
  98.     mov     ax,2510h                ; function 25h - Set new handler
  99.     int     21h                     ; DOS service call
  100. ;===    output the message "program is installed"
  101.     lea     dx,BegMsg               ; DX - address of message
  102.     mov     ah,09h                  ; function 09 - output string
  103.     int     21h                     ; DOS service call
  104. ;===    calculate the size of the resident part 
  105.     lea     dx,BegInst
  106.     add     dx,110h                 ; PSP length plus 16 byte (insurance) 
  107.     mov     cx,4                    ; set counter for shift
  108.     shr     dx,cl                   ; 4 bits to the right - divide by 16
  109.     mov     ax,3100h                ; 31h - terminate and state resident
  110.     int     21h                     ; DOS service call
  111. ;===    Normal exit from program (return code 0)
  112. NormEx: mov     al,0                    ; return code into AL
  113. FullEx: mov     ah,4Ch                  ; function 4Ch - terminate process
  114.     int     21h                     ; DOS service call
  115. ;===    Process situation "Resident part is already installed"
  116. Already:mov     ah,09h                  ; function 09 - output text string
  117.     lea     dx,AlrMsg
  118.     int     21h                     ; DOS service call
  119.     mov     al,1
  120.     jmp     FullEx
  121. ;===    Data for non-resident part of the program
  122. CR      equ     0Ah
  123. LF      equ     0Dh
  124. EndMsg  equ     24h 
  125. BegMsg  db      CR,LF,'      The resident CGA-compatible cursor keeper.       '
  126.     db      CR,LF,'Copyright (C) 1992 V.B.Maljugin,    Russia,    Voronezh'
  127. CRLF    db      CR,LF,EndMsg
  128. AlrMsg  db      CR,LF,'Program has been already installed!',CR,LF,EndMsg
  129. _text   ends
  130.     end     Start
  131.